#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'bed.prefix site_ids'
exit 1
}

while getopts  ":p:f:i:d:" opt; do
case  $opt  in
    p) out_prefix=$OPTARG;;
    f) suffix=$OPTARG;;
    i) bed=$OPTARG;;
    d) depth_filter=$OPTARG;;
    *) info;;
esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

prefix2=$1
# prefix=$1


# extract site
ids=$2
# cat $prefix.bim|cut -f2> $ids

# plink --bfile $prefix --extract $ids --out $prefix.inter --allele1234 --make-bed # ACGT

plink --bfile $prefix2 --extract $ids --out $prefix2.target --allele1234 --make-bed


# cut -f1-2 -d' ' HumanOriginsPublic2068.inter.fam > HumanOriginsPublic2068.samples
# cut -f1-2 -d' ' 1.5.inter.fam > 1.5.samples
# cat 1.5.samples HumanOriginsPublic2068.samples |sort|uniq -d > both.samples
# plink -bfile HumanOriginsPublic2068.inter --remove both.samples --make-bed --out HumanOriginsPublic2068.deldup

# plink --bfile data --flip snp.list --make-bed --out

# plink --bfile $prefix.inter --bmerge $prefix2.inter --merge-mode 4 --out $out_prefix.merge


# echo admixture
# num_thread=4
# labels=$3
# out_prefix=$out_prefix.merge
# cut -f1 $out_prefix.fam > $out_prefix.sample.list
# for k in `seq 4 9`; do
    # admixture -j$num_thread $out_prefix.bed $k > $out_prefix.$k.log
    # sed -i 's/ /\t/g' $out_prefix.$k.Q
    # paste $out_prefix.sample.list $out_prefix.$k.Q > $out_prefix.$k.q
    
    # q_bar.py -p$out_prefix.$k $out_prefix.$k.q $labels
    # q_bar1.py -p$out_prefix.$k $out_prefix.$k.q $labels
# done


. $cmd_done